<?php

namespace app\models;

use Yii;
use yii\base\Model;
/*用户填写手机号码之后，点击获取验证码，网站服务器端自动生成一个随机的数字作为验证码，并临时记录下来，
 *同时将短信内容和用户的手机号码通过验证码短信接口提交到服务商，服务商将短信即时发送到用户的手机；
 *用户接收到短信后，填写验证码，网站服务器将用户填写的验证码和服务器生成的验证码进行比对，如果一致，则验证成功；
 */
/**
 * ContactForm is the model behind the contact form.
 */
class ReguserForm extends Model
{
    public $name;
    public $pw;
    public $phone;
    public $sms;
    public $tjr;
    public $tjcode;//改为存储身份证认证图片地址
    public $sfzimgfile;
    public $is_agree;
    public $realname;
    public $sfzid;
    public $bankcardid;
    public $opencardbank;
    public $alipay;


    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
            [['name', 'pw','phone','sms','tjr','is_agree','realname', 'sfzid', 'bankcardid', 'opencardbank', 'alipay'], 'required'],
            ['phone', 'match', 'pattern'=>'/^1[34578][0-9]{9}$/','message'=>'请输入正确的手机号'],
            ['phone','unique','targetClass'=>'\app\models\Member','message'=>'该手机号码已被注册'],
            ['sms', '\app\validators\SmscodeValidator', 'dowhat' => 'userRegister' ],
            ['name', 'unique', 'targetClass' => '\app\models\Member', 'message' => '抱歉，已被注册，换一个吧.'],
            ['name','match','pattern'=>'/^[0-9a-zA-Z]{5,16}$/','message'=>'用户名必须为英文字母数字组合，至少5位，总长不超过16位'],
            ['pw','match','pattern'=>'/^\d*[^\d]+\d*$/','message'=>'密码不能为纯数字'],
            ['sfzid','match','pattern'=>'/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/','message'=>'请输入正确的身份证号码'],
            ['sfzid','unique','targetClass'=>'\app\models\Member','message'=>'该身份证号码已被注册'],
            //['bankcardid','match','pattern'=>'/^(998801|998802|622525|622526|435744|435745|483536|528020|526855|622156|622155|356869|531659|622157|627066|627067|627068|627069)\d{10}$/','message'=>'请输入正确的银行卡卡号（要求中国银行或中国农业银行或中国建设银行的银行卡卡号）'],
            ['bankcardid','match','pattern'=>
            '/^103\d{16}|'.
            '(623206|621671|620059|621282|621336|621619|622821|622822|622823|622824|622825|622826|622827|622828|622840|622841|622843|622844|622845|622846|622847|622848|622849|623018|620501'.
            '|621660|621661|621663|621667|621668|621666|456351|601382|621256|621212|621283|620061|621725|621330|621331|621332|621333|621297|621568|621569|623208|621620|621756|621757|621758'.
            '|621759|621785|621786|621787|621788|621789|621790|621672|621669|621662|623571|623572|623575|623263|623184|623569|623586|623573|621665|627025|627026|627027|627028|622771|622772'.
            '|622770|622273|622274'.
            '|621284|436742|589970|620060|621081|621467|621598|621621|621700|622280|622700|621673|623211|623668|623094|623669'.
            ')\d{13}|'.
            '(621293|621294|621342|621343|621364|621394|621648|621248|621215|621249|621231|621638|621334|621395'.
            '|421349|434061|434062|524094|526410|552245|621080|621466|621488|621499|622966|622988|621082|623251'.
            ')\d{10}|'.
            '(95595|95596|95597|95598|95599)\d{14}'.
            '$/',
            'message'=>'请输入正确的银行卡卡号'],
            ['bankcardid','unique','targetClass'=>'\app\models\Member','message'=>'该银行卡考号已被注册'],
            ['tjr','exist', 'targetClass' => '\app\models\Member', 'targetAttribute' => 'name','message'=>'推荐人不存在'],
            ['sfzimgfile','file'],

        ];
    }

    /**
     * @return array customized attribute labels
     */
     public function attributeLabels()
     {
         return [
             'name' => '用户名',
             'pw' => '密码',
             'phone' => '手机号',
             'sms' => '手机验证码',
             'tjr' => '推荐人',
             'tjcode' => '推荐码',
             'is_agree' => '已阅读并同意网站使用协议',
             'realname' => '姓名',
             'sfzid' => '身份证号码',
             'bankcardid' => '银行卡号',
             'opencardbank' => '开户行',
             'alipay' => '支付宝账号',
             'sfzimgfile' =>'上传手持本人身份证照片',
         ];
     }

}
